package com.cn.chaomeng.vo.form;

import com.cn.chaomeng.model.Food;
import com.cn.chaomeng.service.IFoodsService;
import com.cn.chaomeng.vo.AjaxError;

/**
 * @author LYJ
 *         Created by Administrator on 2018/3/2 0002.
 */
public class FoodsForm {

    public static Food toFood(FoodsForm foodsForm){
        Food food = new Food();
        food.setFid(foodsForm.getFid());
        food.setTypeid(foodsForm.getTypeid());
        food.setFoodname(foodsForm.getFoodname());
        food.setPicurl(foodsForm.getPicurl());
        food.setFoodprice(foodsForm.getFoodprice());
        food.setFoodvip(foodsForm.getFoodvip());
        food.setFeature(foodsForm.getFeature());
        return food;
    }

    private IFoodsService foodsService;

    private Integer fid;
    private Integer typeid;
    private String foodname;
    private String picurl;
    private Double foodprice;
    private Double foodvip;
    private String feature;

    public FoodsForm(IFoodsService foodsService){
        this.foodsService = foodsService;
    }

    public AjaxError add(){
        AjaxError error = new AjaxError();
        if(typeid == null || emptyType()){
            error.setRecode(1);
        }else if(foodname == null){
            error.setRecode(1);
        }else if(foodprice == null){
            error.setRecode(1);
        }else if(foodvip == null){
            error.setRecode(1);
        }
        return error;
    }

    public AjaxError update(){
        AjaxError error = new AjaxError();
        if(typeid == null || emptyType()){
            error.setRecode(1);
        }else if(foodname == null){
            error.setRecode(1);
        }else if(foodprice == null){
            error.setRecode(1);
        }else if(foodvip == null){
            error.setRecode(1);
        }
        return error;
    }

    public boolean emptyType(){
        return foodsService.selectFoodTypeById(typeid) == null;
    }

    public Integer getFid() {
        return fid;
    }

    public void setFid(Integer fid) {
        this.fid = fid;
    }

    public Integer getTypeid() {
        return typeid;
    }

    public void setTypeid(Integer typeid) {
        this.typeid = typeid;
    }

    public String getFoodname() {
        return foodname;
    }

    public void setFoodname(String foodname) {
        this.foodname = foodname;
    }

    public String getPicurl() {
        return picurl;
    }

    public void setPicurl(String picurl) {
        this.picurl = picurl;
    }

    public Double getFoodprice() {
        return foodprice;
    }

    public void setFoodprice(Double foodprice) {
        this.foodprice = foodprice;
    }

    public Double getFoodvip() {
        return foodvip;
    }

    public void setFoodvip(Double foodvip) {
        this.foodvip = foodvip;
    }

    public String getFeature() {
        return feature;
    }

    public void setFeature(String feature) {
        this.feature = feature;
    }
}
